package com.association.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by keyong on 2020/4/18/018.
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket createRestApi() {
        List<ResponseMessage> msgList = new ArrayList<>();
        msgList.add(new ResponseMessageBuilder().code(200).message("成功").build());
        msgList.add(new ResponseMessageBuilder().code(400).message("找不到资源").build());
        msgList.add(new ResponseMessageBuilder().code(500).message("服务器内部错误").build());

        return new Docket(DocumentationType.SWAGGER_2)
                .enable(false)
                .globalResponseMessage(RequestMethod.GET, msgList)
                .globalResponseMessage(RequestMethod.POST, msgList)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.yto.courier.api.controller"))
                .paths(PathSelectors.any())
                .build();
    }

}
